// MouseSettingsDialog.cpp : implementation file
//

#include "stdafx.h"
#include "OpenGL.h"
#include "MouseSettingsDialog.h"
#include "afxdialogex.h"


// CMouseSettingsDialog dialog

IMPLEMENT_DYNAMIC(CMouseSettingsDialog, CDialogEx)

CMouseSettingsDialog::CMouseSettingsDialog(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMouseSettingsDialog::IDD, pParent)
    , m_nTickFrequency(3)
    , m_nSensitivitySliderRangeMin(  1)
    , m_nSensitivitySliderRangeMax(100)

    , m_fSensitivityRangeMin(0.01f)
    , m_fSensitivityRangeMax(1.00f)

    , m_fRotSensitivityFactor(1.00f)
    , m_fTraSensitivityFactor(1.00f)
    , m_fScaSensitivityFactor(1.00f)

    , m_nRotSensitivitySliderPos(0)
    , m_nTraSensitivitySliderPos(0)
    , m_nScaSensitivitySliderPos(0)
{
    // calculate the default position for each slider
    restoreDefaults();
}


CMouseSettingsDialog::~CMouseSettingsDialog()
{
}


void CMouseSettingsDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_ROTATION_SENSITIVITY,    m_RotSensitivityControl);
    DDX_Control(pDX, IDC_TRANSLATION_SENSITIVITY, m_TraSensitivityControl);
    DDX_Control(pDX, IDC_SCALE_SENSITIVITY,       m_ScaSensitivityControl);
}


BEGIN_MESSAGE_MAP(CMouseSettingsDialog, CDialogEx)
    ON_BN_CLICKED(IDOK,                 &CMouseSettingsDialog::OnBnClickedOk)
    ON_BN_CLICKED(IDC_RESTORE_DEFAULTS, &CMouseSettingsDialog::OnBnClickedRestoreDefaults)
END_MESSAGE_MAP()


// CMouseSettingsDialog message handlers


BOOL CMouseSettingsDialog::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    // TODO:  Add extra initialization here
    m_RotSensitivityControl.SetRangeMin(m_nSensitivitySliderRangeMin);
    m_RotSensitivityControl.SetRangeMax(m_nSensitivitySliderRangeMax);
    m_RotSensitivityControl.SetTicFreq(m_nTickFrequency);
    m_RotSensitivityControl.SetPos(m_nRotSensitivitySliderPos);

    m_TraSensitivityControl.SetRangeMin(m_nSensitivitySliderRangeMin);
    m_TraSensitivityControl.SetRangeMax(m_nSensitivitySliderRangeMax);
    m_TraSensitivityControl.SetTicFreq(m_nTickFrequency);
    m_TraSensitivityControl.SetPos(m_nTraSensitivitySliderPos);

    m_ScaSensitivityControl.SetRangeMin(m_nSensitivitySliderRangeMin);
    m_ScaSensitivityControl.SetRangeMax(m_nSensitivitySliderRangeMax);
    m_ScaSensitivityControl.SetTicFreq(m_nTickFrequency);
    m_ScaSensitivityControl.SetPos(m_nScaSensitivitySliderPos);

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}


void CMouseSettingsDialog::OnBnClickedOk()
{
    m_nRotSensitivitySliderPos = m_RotSensitivityControl.GetPos();
    m_nTraSensitivitySliderPos = m_TraSensitivityControl.GetPos();
    m_nScaSensitivitySliderPos = m_ScaSensitivityControl.GetPos();

    CDialogEx::OnOK();
}


void CMouseSettingsDialog::OnBnClickedRestoreDefaults()
{
    restoreDefaults();

    m_RotSensitivityControl.SetPos(m_nRotSensitivitySliderPos);
    m_TraSensitivityControl.SetPos(m_nTraSensitivitySliderPos);
    m_ScaSensitivityControl.SetPos(m_nScaSensitivitySliderPos);
}
